package cn.hdustea.shopNavigation.ui.view.bottom.mine

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import cn.hdustea.shopNavigation.BuildConfig
import cn.hdustea.shopNavigation.R
import cn.hdustea.shopNavigation.config.ConfigKey
import cn.hdustea.shopNavigation.ui.view.main.HomeActivity
import com.hdustea.base.util.GlideCacheUtil
import com.hdustea.base.util.ToastUtil
import com.hdustea.base.widget.DoubleDialog
import kotlinx.android.synthetic.main.activity_setting.*

class SettingActivity : AppCompatActivity() {
    private lateinit var mExitDialog: DoubleDialog

    companion object {

        fun startActivity(context: Context) {
            context.startActivity(Intent(context, SettingActivity::class.java))
        }

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_setting)
        init()
    }

    @SuppressLint("SetTextI18n")
    private fun init() {
        mExitDialog = DoubleDialog(this)
        mExitDialog.setContent("确定要退出吗？")
        mExitDialog.confirmText("确定退出")
        mExitDialog.cancelText("我再逛逛")
        mExitDialog.confirmListener(View.OnClickListener {
            mExitDialog.dismiss()
            ConfigKey.clearUserInfo()
            HomeActivity.startActivity(this)
            finish()
        })
        tv_setting_cache.text = GlideCacheUtil.getInstance().getCacheSize(this)
        rl_clear_cache.setOnClickListener {
            GlideCacheUtil.getInstance().clearImageAllCache(this)
            ToastUtil.showShort("已清除缓存")
            tv_setting_cache.text = GlideCacheUtil.getInstance().getCacheSize(this)
        }
        tv_setting_ver.text = "v${BuildConfig.VERSION_NAME}"
        btn_setting_log_out.setOnClickListener {
            mExitDialog.show()
        }
    }

}